#!/usr/bin/env python
# encoding: utf-8
"""
@author:zwb
@file: user_authentication.py
@contact: zwb15083976291@163.com
@time: 2021/11/14
"""
import functools

from django.http import JsonResponse
from rest_framework import status
from common.models import BlogUser
from utils.responses import CommonResponse, CommonAPIResponseStatus


def allow_admin_user(func):
    @functools.wraps(func)
    def wrapper(request, *args, **kwargs):
        if not isinstance(getattr(request, 'auth_user', ''), BlogUser):
            data = dict(zip(('code', 'message'), CommonAPIResponseStatus.ACCESS_DENIED.value))
            return JsonResponse(data=data, status=status.HTTP_403_FORBIDDEN)
        return func(request, *args, **kwargs)

    return wrapper
